package com.kevin.j2eeToolBox.thread.concurren;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecutorTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		// ExecutorService thread = Executors.newFixedThreadPool(5);
		ExecutorService thread = Executors.newCachedThreadPool();

		for (int i = 0; i < 10; i++) {
			final int currentId = i;

			thread.execute(new Runnable() {

				@Override
				public void run() {

					for (int i = 0; i < 10; i++) {

						try {
							Thread.sleep(1000);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						System.out.println(Thread.currentThread().getName()
								+ "   " + " current thread id" + currentId
								+ "   loop id " + i);
					}

				}
			});

		}
	}
}
